package com.hs.demo.mina;


import org.apache.mina.core.service.IoAcceptor;
import org.apache.mina.transport.socket.nio.NioSocketAcceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.net.InetSocketAddress;

@Component
public class MinaServer {
    @Value("${listen}")
    String listen;

    @Autowired
    private SenMessageService senMessageServiceX;
    public static boolean isRun = false;
    public void start() throws IOException {
        IoAcceptor acceptor = new NioSocketAcceptor();
        acceptor.setHandler(new TimeServerHandler(senMessageServiceX));
        acceptor.bind(new InetSocketAddress(Integer.valueOf(listen)));
        isRun = true;
        System.out.println("监听端口:" + listen);
    }
}

